﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GridViewCellLookup.aspx.cs"
    Inherits="EnumDataSourceControlTest.GridViewCellLookup" %>

<%@ Register Assembly="Salient.EnumDataSourceControl20" Namespace="Salient.Web.UI.WebControls"
    TagPrefix="ss" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="include/CodeStyles.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>
            Salient.Web.UI.WebControls20</h1>
        <h2>
            EnumDataSource</h2>
        <p>
            Author: Sky Sanders - <a href="mailto:sky.sanders@gmail.com">
            sky.sanders@gmail.com</a></p>
        <h5>
            Bound Grid Cell Lookup:</h5>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id"
            DataSourceID="SqlDataSource1">
            <Columns>
                <asp:CommandField ShowEditButton="True" />
                <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True"
                    SortExpression="id" />
                <asp:BoundField DataField="SubscriptionType" HeaderText="SubscriptionType DB Value"
                    SortExpression="SubscriptionType" />
                <asp:TemplateField HeaderText="SubscriptionType Lookup" SortExpression="SubscriptionType">
                    <EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataMember="EnumDataSourceControlQuickStart.SubscriptionType"
    DataSourceID="EnumDataSource1" DataTextField="Description" DataValueField="IntegralValue"
    SelectedValue='<%# Bind("SubscriptionType") %>'>
</asp:DropDownList>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# EnumDataSource1.GetDescription("EnumDataSourceControlQuickStart.SubscriptionType",Eval("SubscriptionType")) %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Customer" HeaderText="Customer" SortExpression="Customer" />
            </Columns>
            <EmptyDataTemplate>
                No Data
            </EmptyDataTemplate>
        </asp:GridView>
        <p>
            The ItemTemplate:Label calls GetDescription on the EnumDataSource to display the 
            current value of the field.</p>
        <p>
            The EditItemTemlate DropDownList binds SelectedValue to the SqlDataSource and 
            the content properties to the EnumDataSource&nbsp;
        </p>
            
<div class='Code'>
            <div class='CodeSectionTop'>
            </div>
            <div class='CodeSectionBody'>
        <p class="MsoNormal">
            <span style="font-size:8.0pt;line-height:115%;font-family:
Consolas;mso-bidi-font-family:&quot;Times New Roman&quot;;color:blue;mso-no-proof:yes">&lt;</span><span style="font-size:8.0pt;line-height:115%;font-family:Consolas;mso-bidi-font-family:
&quot;Times New Roman&quot;;color:#A31515;mso-no-proof:yes">asp</span><span style="font-size:8.0pt;line-height:115%;font-family:Consolas;mso-bidi-font-family:
&quot;Times New Roman&quot;;color:blue;mso-no-proof:yes">:</span><span style="font-size:
8.0pt;line-height:115%;font-family:Consolas;mso-bidi-font-family:&quot;Times New Roman&quot;;
color:#A31515;mso-no-proof:yes">Label</span><span style="font-size:8.0pt;
line-height:115%;font-family:Consolas;mso-bidi-font-family:&quot;Times New Roman&quot;;
mso-no-proof:yes"> <span style="color:red">ID</span><span style="color:blue">=&quot;Label1&quot;</span>
            <span style="color:red">runat</span><span style="color:blue">=&quot;server&quot;</span>
            <span style="color:red">
            <br />
&nbsp;&nbsp;&nbsp; Text</span><span style="color:blue">=&#39;</span><span 
                style="background: yellow; mso-highlight: yellow">&lt;%</span># 
            EnumDataSource1.GetDescription(&quot;EnumDataSourceControlQuickStart.SubscriptionType&quot;,Eval(&quot;SubscriptionType&quot;))
            <span style="background: yellow; mso-highlight: yellow">%&gt;</span><span 
                style="color:blue">&#39;&gt;<br />
            &lt;/</span><span style="color:#A31515">asp</span><span style="color:blue">:</span><span 
                style="color:#A31515">Label</span><span style="color:blue">&gt;</span></span></p>

        <p class="MsoNormal">
            <span style="font-size:
8.0pt;font-family:Consolas;mso-bidi-font-family:&quot;Times New Roman&quot;;color:blue;
mso-no-proof:yes">&lt;</span><span style="font-size:8.0pt;font-family:Consolas;
mso-bidi-font-family:&quot;Times New Roman&quot;;color:#A31515;mso-no-proof:yes">asp</span><span style="font-size:8.0pt;font-family:Consolas;mso-bidi-font-family:&quot;Times New Roman&quot;;
color:blue;mso-no-proof:yes">:</span><span style="font-size:8.0pt;font-family:
Consolas;mso-bidi-font-family:&quot;Times New Roman&quot;;color:#A31515;mso-no-proof:
yes">DropDownList</span><span style="font-size:8.0pt;font-family:Consolas;
mso-bidi-font-family:&quot;Times New Roman&quot;;mso-no-proof:yes"> <span style="color:red">
            ID</span><span style="color:blue">=&quot;DropDownList1&quot;</span>
            <span style="color:red">runat</span><span style="color:blue">=&quot;server&quot;</span>
            <span style="color:red">DataMember</span><span style="color:blue">=&quot;EnumDataSourceControlQuickStart.SubscriptionType&quot;<o:p><br />
            </o:p>
            </span></span>
            <span style="font-size:
8.0pt;font-family:Consolas;mso-bidi-font-family:&quot;Times New Roman&quot;;mso-no-proof:
yes"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span><span style="color:red">
            DataSourceID</span><span style="color:blue">=&quot;EnumDataSource1&quot;</span>
            <span style="color:red">DataTextField</span><span style="color:blue">=&quot;Description&quot;</span>
            <span style="color:red">DataValueField</span><span style="color:blue">=&quot;IntegralValue&quot;<o:p><br />
            </o:p>
            </span><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>
            <span style="color:red">SelectedValue</span><span style="color:blue">=&#39;</span><span 
                style="background: yellow; mso-highlight: yellow">&lt;%</span># 
            Bind(&quot;SubscriptionType&quot;) <span style="background: yellow; mso-highlight: yellow">
            %&gt;</span><span style="color:blue">&#39;&gt;<o:p><br />
            </o:p>
            </span></span>
            <span style="font-size:8.0pt;line-height:115%;font-family:
Consolas;mso-bidi-font-family:&quot;Times New Roman&quot;;color:blue;mso-no-proof:yes">&lt;/</span><span style="font-size:8.0pt;line-height:115%;font-family:Consolas;mso-bidi-font-family:
&quot;Times New Roman&quot;;color:#A31515;mso-no-proof:yes">asp</span><span style="font-size:8.0pt;line-height:115%;font-family:Consolas;mso-bidi-font-family:
&quot;Times New Roman&quot;;color:blue;mso-no-proof:yes">:</span><span style="font-size:
8.0pt;line-height:115%;font-family:Consolas;mso-bidi-font-family:&quot;Times New Roman&quot;;
color:#A31515;mso-no-proof:yes">DropDownList</span><span style="font-size:8.0pt;
line-height:115%;font-family:Consolas;mso-bidi-font-family:&quot;Times New Roman&quot;;
color:blue;mso-no-proof:yes">&gt;</span></p>
            
            </div>
            <div class='CodeSectionBottom'>
                <div class='Title'>
                     </div>
            </div>
        </div>            
 
        
        <p>
        </p>
        <div class='Code'>
            <div class='CodeSectionTop'>
            </div>
            <div class='CodeSectionBody'>
                <div style="font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt;
                    color: black; background: white; color: black; background-color: transparent;
                    /*white-space: pre; */  	width: 488px;">
                    <p style="margin: 0px;">
                        <span style="color: blue;">using</span> System.ComponentModel;</p>
                    <p style="margin: 0px;">
                        &nbsp;</p>
                    <p style="margin: 0px;">
                        <span style="color: blue;">namespace</span> EnumDataSourceControlQuickStart</p>
                    <p style="margin: 0px;">
                        {</p>
                    <p style="margin: 0px;">
                        &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">
                            enum</span> <span style="color: #2b91af;">SubscriptionType</span></p>
                    <p style="margin: 0px;">
                        &nbsp;&nbsp;&nbsp; {</p>
                    <p style="margin: 0px;">
                        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [<span style="color: #2b91af;">Description</span>(<span
                            style="color: #a31515;">"Unknown"</span>)]</p>
                    <p style="margin: 0px;">
                        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; unknown = 0,</p>
                    <p style="margin: 0px;">
                        &nbsp;</p>
                    <p style="margin: 0px;">
                        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: green;">// note this value
                            has no description attribute</span></p>
                    <p style="margin: 0px;">
                        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: green;">// EnumDataSource
                            will populate Description with the </span>
                    </p>
                    <p style="margin: 0px;">
                        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: green;">// name.</span></p>
                    <p style="margin: 0px;">
                        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; retail,</p>
                    <p style="margin: 0px;">
                        &nbsp;</p>
                    <p style="margin: 0px;">
                        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [<span style="color: #2b91af;">Description</span>(<span
                            style="color: #a31515;">"Evaluation"</span>)]</p>
                    <p style="margin: 0px;">
                        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; evaluation,</p>
                    <p style="margin: 0px;">
                        &nbsp;</p>
                    <p style="margin: 0px;">
                        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [<span style="color: #2b91af;">Description</span>(<span
                            style="color: #a31515;">"Internal Use Only"</span>)]</p>
                    <p style="margin: 0px;">
                        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; internalonly</p>
                    <p style="margin: 0px;">
                        &nbsp;&nbsp;&nbsp; }
                    </p>
                    <p style="margin: 0px;">
                        }
                    </p>
                </div>
            </div>
            <div class='CodeSectionBottom'>
                <div class='Title'>
                    SubscriptionType.cs</div>
            </div>
        </div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FROM [Subscriptions] WHERE [id] = @original_id AND (([SubscriptionType] = @original_SubscriptionType) OR ([SubscriptionType] IS NULL AND @original_SubscriptionType IS NULL)) AND [Customer] = @original_Customer"
            InsertCommand="INSERT INTO [Subscriptions] ([SubscriptionType], [Customer]) VALUES (@SubscriptionType, @Customer)"
            OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [Subscriptions]"
            UpdateCommand="UPDATE [Subscriptions] SET [SubscriptionType] = @SubscriptionType, [Customer] = @Customer WHERE [id] = @original_id AND (([SubscriptionType] = @original_SubscriptionType) OR ([SubscriptionType] IS NULL AND @original_SubscriptionType IS NULL)) AND [Customer] = @original_Customer">
            <DeleteParameters>
                <asp:Parameter Name="original_id" Type="Int32" />
                <asp:Parameter Name="original_SubscriptionType" Type="Int32" />
                <asp:Parameter Name="original_Customer" Type="String" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="SubscriptionType" Type="Int32" />
                <asp:Parameter Name="Customer" Type="String" />
                <asp:Parameter Name="original_id" Type="Int32" />
                <asp:Parameter Name="original_SubscriptionType" Type="Int32" />
                <asp:Parameter Name="original_Customer" Type="String" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="SubscriptionType" Type="Int32" />
                <asp:Parameter Name="Customer" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>
        <ss:EnumDataSource ID="EnumDataSource1" runat="server">
        </ss:EnumDataSource>
    </div>
    </form>
</body>
</html>
